﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace KalenderTradisional
{
    public class Kalender
    {
        DateTime calendar=System.DateTime.Now;

        private Jawa jawa;
        private Chinese chinese;
        private Masehi masehi;
        //public enum tipe { Masehi, Jawa, Chinese };
        public int cal;

        public Kalender(int thn,int bln,int tgl)
        {
            calendar = new DateTime(thn, bln, tgl);   
            jawa = new Jawa(calendar.Year, calendar.Month, calendar.Day);
            chinese = new Chinese(calendar.Year, calendar.Month, calendar.Day);
            masehi = new Masehi(calendar.Year, calendar.Month, calendar.Day);
            cal = 0;
        }

        public void goTo(int thn, int bln, int tgl)
        {
            calendar = new DateTime(thn, bln, tgl);
            update();
        }

        public void addHari(int val)
        {
            calendar=calendar.AddDays(val);
            update();
        }

        

        public void addBulan(int val)
        {
            calendar=calendar.AddMonths(val);
            update();
        }

        public void addTahun(int val)
        {
            calendar=calendar.AddYears(val);
            update();
        }

        public string showJawa(int tahun,int bulan,int tanggal)
        {
            string tamp="";
            Jawa temp=new Jawa(tahun,bulan,tanggal);
            tamp += temp.getTanggal() + " - " + temp.getBulan() + " - " + temp.getTahun();
            return tamp;
        }

        public string showChinese(int tahun, int bulan, int tanggal)
        {
            string tamp = "";
            Chinese temp = new Chinese(tahun, bulan, tanggal);
            tamp += temp.getTanggal() + " - " + temp.getBulan() + " - " + temp.getTahun();
            return tamp;
        }

        
        private void update()
        {
            jawa.setTahun(calendar.Year);
            chinese.setTahun(calendar.Year);
            masehi.setTahun(calendar.Year);

            jawa.setBulan(calendar.Month);
            chinese.setBulan(calendar.Month);
            masehi.setBulan(calendar.Month);

            jawa.setTanggal(calendar.Day);
            chinese.setTanggal(calendar.Day);
            masehi.setTanggal(calendar.Day);

            jawa.setHari((int)calendar.DayOfWeek);
            chinese.setHari((int)calendar.DayOfWeek);
            masehi.setHari((int)calendar.DayOfWeek);

            jawa.setKalender(calendar.Year, calendar.Month, calendar.Day, (int)calendar.DayOfWeek);
            chinese.setKalender(calendar.Year, calendar.Month, calendar.Day, (int)calendar.DayOfWeek);
            masehi.setKalender(calendar.Year, calendar.Month, calendar.Day, (int)calendar.DayOfWeek);
        }

        public void setToMasehi()
        {
            this.cal = 0;
        }

        public void setToJawa()
        {
            this.cal = 1;
        }

        public void setToChinese()
        {
            this.cal = 2;
        }
        public string getHari()
        {
            switch (cal)
            {
                case 0: return masehi.getHari(); 
                case 1: return jawa.getHari(); 
                case 2: return chinese.getHari(); 
                default: return ""; 
            }
        }

        public string getTanggal()
        {
            switch (cal)
            {
                case 0: return masehi.getTanggal(); 
                case 1: return jawa.getTanggal();
                case 2: return chinese.getTanggal(); 
                default: return ""; 
            }
        }

        public string getBulan()
        {
            switch (cal)
            {
                case 0: return masehi.getBulan(); 
                case 1: return jawa.getBulan(); 
                case 2: return chinese.getBulan();
                default: return ""; 
            }
        }

        public string getTahun()
        {
            switch (cal)
            {
                case 0: return masehi.getTahun(); 
                case 1: return jawa.getTahun(); 
                case 2: return chinese.getTahun(); 
                default: return ""; 
            }
        }
    }
}
